<!-- extend from base layout -->
{% extends "base.html" %}

{% block content %}
<h1>Hi, {{g.user.nickname}}!</h1>
<form action="" method="post" name="post" class="form-horizontal">
    <fieldset>
        <legend>Say Something</legend>
        <div class="form-group">
            <label for="post" class="col-sm-2 required">Say</label>
            <div class="col-sm-6">
                {{form.hidden_tag()}}
                <input type="text" class="form-control" id="post" name="post" placeholder="Something" />
            </div>
        </div>
        {% if form.errors.post %}
            {% for error in form.errors.post %}
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-6">
                    <div class="alert alert-danger with-icon alert-dismissable">
                        <i class="icon-frown"></i>
                        <div class="content">
                            Error: [{{ error }}]
                        </div>
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    </div>
                </div>
            </div>
            {% endfor %}
        {% endif %}
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-6">
                <button type="submit" class="btn btn-default">Post</button>
            </div>
        </div>
    </fieldset>
</form>

<!-- Posts Table -->
<table class="table table-hover table-auto">
    <!-- posts is a Paginate object -->
    {% for post in posts.items %}
        {% include 'post.html' %}
    {% endfor %}
</table>

<!-- 分页 -->
<ul class="pager">
    {% if posts.has_prev %}
    <li>
        <a href="{{ url_for('index', page = posts.prev_num) }}" aria-label="Previous">
            <span aria-hidden="true">&laquo;</span> Newer
        </a>
    </li>
    {% else %}
    <li class="disabled">
        <a href="#" aria-label="Previous">
            <span aria-hidden="true">&laquo;</span> Newer
        </a>
    </li>
    {% endif %}

    {% if posts.has_next %}
    <li>
        <a href="{{ url_for('index', page = posts.next_num) }}" aria-label="Next">
            Older <span aria-hidden="true">&raquo;</span>
        </a>
    </li>
    {% else %}
    <li class="disabled">
        <a href="#" aria-label="Previous">
            Older <span aria-hidden="true">&raquo;</span>
        </a>
    </li>
    {% endif %}
</ul>
{% endblock %}